namespace BoxPlayer
{
    class T_Box_Video_Multithread;         //
    class T_Box_Video_Multithread_Slice;   //
    class T_Box_Video_Multithread_Manager; //
    class T_Box_Video_Multithread_Context;  //
};

#ifndef T_BOX_VIDEO_H
#define T_BOX_VIDEO_H

#include "stable.h"
#include "t_box_context.h"

namespace BoxPlayer
{
    class T_Box_Video_Multithread
    {
    public:
        enum
        {
            //NUM_THREAD = 3,
            NUM_THREAD = 2,
            //NUM_THREAD = 1,
        };
    };

    class T_Box_Video_Multithread_Slice : public T_SharedPointerQueue<T_AV_Packet>
    {
    protected:
        qint64 m_timing;
        //bool m_complete;
    public:
        explicit T_Box_Video_Multithread_Slice(qint64 a_timing)
            : m_timing(a_timing)
            //, m_complete(false)
        {
            qDebug() << "[T_Box_Video_Multithread_Slice::T_Box_Video_Multithread_Slice()]" << m_timing;
        }
        virtual ~T_Box_Video_Multithread_Slice()
        {
            qDebug() << "[this->size()]" << this->size();
        }
        qint64 timing()
        {
            return m_timing;
        }
#if 0x0
        bool &complete()
        {
            return m_complete;
        }
#endif
    };

    class T_Box_Video_Multithread_Manager : public T_Box_Context
    {
        Q_OBJECT
    protected:
        QList<T_Box_Video_Multithread_Context *> m_context_list;
        T_SharedPointerQueue<T_Box_Video_Multithread_Slice> m_total_queue;
        T_SharedPointerQueue<T_Box_Video_Multithread_Slice> m_work_queue;
        T_SharedPointerQueue<T_Box_Video_Multithread_Slice> m_render_queue;
        T_SharedPointerQueue<T_AV_Packet> m_packet_queue;
    public:
        explicit T_Box_Video_Multithread_Manager(T_Box_Core *a_core);
        virtual ~T_Box_Video_Multithread_Manager();
        void reset()
        {
            T_ATOMIC_LOCKER(v_atom, this);
            //abandon decode slice here
            this->totalQueue()->clear();
            this->workerQueue()->clear();
            this->renderQueue()->clear();
            this->packetQueue()->clear();
        }
        virtual qint64 seekMe(T_Box_Seek_Manager *a_seek_mgr, qint64 a_msec);
        T_SharedPointerQueue<T_Box_Video_Multithread_Slice> *workerQueue()
        {
            return &m_work_queue;
        }
        T_SharedPointerQueue<T_Box_Video_Multithread_Slice> *totalQueue()
        {
            return &m_total_queue;
        }
        T_SharedPointerQueue<T_Box_Video_Multithread_Slice> *renderQueue()
        {
            return &m_render_queue;
        }
        T_SharedPointerQueue<T_AV_Packet> *packetQueue()
        {
            return &m_packet_queue;
        }
    protected:
        virtual void run();
    };

    class T_Box_Video_Multithread_Context : public T_Box_Context
    {
    protected:
        T_Box_Video_Multithread_Manager *m_manager;
        int m_index;
        QSharedPointer<T_Box_Video_Multithread_Slice> m_slice;
    public:
        explicit T_Box_Video_Multithread_Context(T_Box_Video_Multithread_Manager *a_manager, int a_index);
        virtual ~T_Box_Video_Multithread_Context();
        void reset();
        virtual qint64 seekMe(T_Box_Seek_Manager *a_seek_mgr, qint64 a_msec);
        QSharedPointer<T_Box_Video_Multithread_Slice> slice();
    protected:
        virtual void run();
    };
};
#endif // T_BOX_VIDEO_H
